cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 14)

# 项目名称
project(SolverTask LANGUAGES CXX)

set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -Wa,-mbig-obj")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall -Wa,-mbig-obj")

# 获取源文件
file(GLOB SOURCES 
    ${CMAKE_CURRENT_SOURCE_DIR}/Common/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/Solver/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/Static/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/Modes/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/Buckling/*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/Thermal/*.cpp)

## kernel sources
set(kernel_SRCS
    Kernel/KernelModule.h
    Kernel/Time.h
    Kernel/Time.cpp
    Kernel/TimeIndex.h
    Kernel/TimeIndex.cpp  
    Kernel/Variable.h
    Kernel/Variable.cpp
    Kernel/Domain.h
    Kernel/Domain.cpp 

    Kernel/MModel.h
    Kernel/MModel.cpp
    Kernel/MSolver.h
    Kernel/MSolver.cpp
    Kernel/TransientTask.h
    Kernel/TransientTask.cpp
    Kernel/NonLinearTask.h
    Kernel/NonLinearTask.cpp

    Kernel/MTRAModel.h
    Kernel/MTRAModel.cpp
    Kernel/ResponseSpectrumAnalysisTask.h
    Kernel/ResponseSpectrumAnalysisTask.cpp
)
list(APPEND SOURCES ${kernel_SRCS})

# 添加动态库
add_library(${PROJECT_NAME} SHARED ${SOURCES})

# 添加头文件目录
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})

# 添加链接库
target_link_libraries(${PROJECT_NAME}
    PRIVATE Logging
    PRIVATE Configuration
    PRIVATE Exception
    PRIVATE Algebra
    PRIVATE DataStructure
    PRIVATE DBManager
    PRIVATE Framework
    PRIVATE Integration
    PRIVATE BeamSecPropCalculator
    PRIVATE ElementCalculator
    PRIVATE PublicElement
    PRIVATE ADVEleCalculator
    PRIVATE ConnectElementCalculator
    PRIVATE Constraint
)

if(SG_LICENSE_CHECK)
    add_definitions(-DSG_LICENSE_CHECK)
    target_link_libraries(${PROJECT_NAME} PRIVATE Security)
endif()

import_boost()
target_link_libraries(${PROJECT_NAME} PRIVATE Algebra)

# 添加编译选项
target_compile_definitions(${PROJECT_NAME} PRIVATE EXPORTING_Task)

# 安装头文件
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Common/   DESTINATION include/SGFem/Task/Common/   FILES_MATCHING PATTERN "*.h" PATTERN "test" EXCLUDE)
install(FILES     ${CMAKE_CURRENT_SOURCE_DIR}/Solver/FEMSolve.h DESTINATION include/SGFem/Task/Solver)
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Buckling/ DESTINATION include/SGFem/Task/Buckling/ FILES_MATCHING PATTERN "*.h" PATTERN "test" EXCLUDE)
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Thermal/ DESTINATION include/SGFem/Task/Thermal/ FILES_MATCHING PATTERN "*.h" PATTERN "test" EXCLUDE)

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/Static/test/测试案例说明.md DESTINATION Manual/TestReport/)

# 安装目标
install(TARGETS ${PROJECT_NAME}
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin)

# 添加单元测试子项目
if(SG_BUILD_UNIT_TEST)
    add_subdirectory(test)
endif()
